<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-input placeholder="选择查看的产品！" v-model="goods.name" disabled style="width:300px">
                <el-button slot="append" icon="el-icon-search" @click="getinfo()" v-qx="quanxian.sele"></el-button>
            </el-input>
            <el-input v-model="kucun" disabled style="width:300px">
                <el-button slot="prepend">当前库存</el-button>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="ID" width="80"></el-table-column>
            <el-table-column prop="ordertype" label="出入类型">
                <template slot-scope="scope">
                    <el-tag size="mini" type="success" v-if="scope.row.ordertype == 'RKD'">入库</el-tag>
                    <el-tag size="mini" type="gray" v-if="scope.row.ordertype == 'CKD'">出库</el-tag>
                    <el-tag size="mini" type="primary" v-if="scope.row.ordertype == 'LLD'">领料</el-tag>
                    <el-tag size="mini" type="warning" v-if="scope.row.ordertype == 'TLD'">退料</el-tag>
                    <el-tag size="mini" type="danger" v-if="scope.row.ordertype == 'LSD'">开单</el-tag>
                    <el-tag size="mini" type="danger" v-if="scope.row.ordertype == 'KKD'">开卡</el-tag>
                    <el-tag size="mini" type="danger" v-if="scope.row.ordertype == 'CZD'">充值</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="nums" label="数量"></el-table-column>
            <el-table-column prop="addtime" label="开单日期">
                <template slot-scope="scope">
                    {{scope.row.addtime|hourTime}}
                </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
                <template slot-scope="scope">
                    <el-button type="info" icon="el-icon-h-chakan" size="mini" @click="chakan(scope.row)" v-qx="quanxian.look"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :page-sizes="[15, 30, 50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
import P from '@/service/shop/popup.js'

export default {
  name: 'stockLog',
  data () {
    return {
      list: [],
      currentPage: 1,
      pageSize: 15,
      total: 0,
      search: '',
      goods: {
        id: 0,
        name: ''
      },
      kucun: 0,
      quanxian: {
        sele: 'stocklog_sele',
        look: 'stocklog_look'
      }
    }
  },
  methods: {
    getinfo: async function () {
      let data = await P.typeGoodsPopup({ rowtype: 1 })
      if (data) {
        this.goods = {
          id: data.id,
          name: data.name
        }
        this.getList(this.currentSize, this.pageSize, this.goods.id)
      }
    },
    chakan: async function (row) {
      let obj = { id: row.orderid, ordertype: row.ordertype }
      await P.showOrderPopup(obj)
    },
    sizeChange: function (val) {
      this.pageSize = val
      this.getList(this.currentPage, val, this.goods.id)
    },
    currentChange: function (val) {
      this.currentPage = val
      this.getList(val, this.pageSize, this.goods.id)
    },
    getList: async function (pages, limits, goodsid) {
      let data = await C.ajax('/shop/stock/getgoodslogs', { pages: pages, limits: limits, goodsid: goodsid }, 'post')
      if (data) {
        this.list = data.list.data
        this.total = data.list.count
        this.kucun = data.goods.nums
      }
    }
  }
}
</script>